﻿<html>
    <head>
<meta http-equiv="X-UA-Compatible" content="IE=9" />
        <title>Image Comparison Tool</title>
<script type="text/javascript" src="range.js"></script>
<script type="text/javascript" src="timer.js"></script>
<script type="text/javascript" src="slider.js"></script>     
<script language="javascript" src="../ToolsCommon.js"></script>
 
<link type="text/css" rel="StyleSheet" href="slider.css" />  
<link type="text/css" rel="StyleSheet" href="../Style.css" />  
 <style>
        .directionSelect
        {width: 80px; color:White; background-color:#535353;   border: 2px double white;}
        .NormalText 
        {font-family:  Arial, Helvetica, sans-serif; font-size: 12px; font-style: normal; font-weight: normal; color: #ffffff; text-decoration: none;}
        .LayerHeader 
        {font-family:  Arial, Helvetica, sans-serif; font-size: 16px; font-style: italic; font-weight: normal; color: #ffffff; text-decoration: none;}
    </style>

    <object id="SGWorld" classid="CLSID:3a4f919c-65a8-11d5-85c1-0001023952c1">
    </object>

<script language="jscript">

    var lastlevel = 100;
    var ImageryLayerObj = null;
    var ImageryLayerGeometry;
    var AutoOnOff = false;
    var Cliptimeout;
    var ClipUpdatetimeout;
    var clipPosition;
    var sliderClip;


    //--------------
    // 
    function Init() {
        var ObjectID = "";
        try {

            ObjectID = FindImageryLayer();
            if (ObjectID == "") {
                ////  need to display the error message div
                document.getElementById("alertDiv").style.visibility = "visible";
                return;
            }

            document.getElementById("mainDiv").style.visibility = "visible";
            ImageryLayerObj = SGWorld.Creator.GetObject(ObjectID);
            document.getElementById("LayerNameSpan").innerHTML = ImageryLayerObj.TreeItem.Name + " " + ImageryLayerObj.ID;

            ImageryLayerGeometry = ImageryLayerObj.Geometry.Clone();


            sliderClip = new Slider(document.getElementById("sliderClip"), document.getElementById("sliderClipID"));
            sliderClip.setValue(100);
            sliderClip.setMinimum(0);
            sliderClip.setMaximum(100);
            sliderClip.onchange = function () {
                SetClipTrans(sliderClip.getValue(), false);
            };

            SGWorld.SetParam(450, 1);
        }
        catch (e) { alert(SGLang.i18n("Text20") + e.message); }
    }

    //------------
    // FindImageryLayer
    function FindImageryLayer() {
        var ObjectID = "";
        var TEObj;

        var centerPoint;

        try {

            // Try to detect if center of the screen points to a valid imagery layer

            ObjectID = DetectImageryLayer(SGWorld.Window.Rect.Width / 2, SGWorld.Window.Rect.Height / 2);
            if (ObjectID != "")
                return ObjectID;
            ObjectID = DetectImageryLayer(0, 0);
            if (ObjectID != "")
                return ObjectID;
            ObjectID = DetectImageryLayer(SGWorld.Window.Rect.Width - 2, 0);
            if (ObjectID != "")
                return ObjectID;
            ObjectID = DetectImageryLayer(SGWorld.Window.Rect.Width - 2, SGWorld.Window.Rect.Height - 20);
            if (ObjectID != "")
                return ObjectID;
            ObjectID = DetectImageryLayer(0, SGWorld.Window.Rect.Height - 20);
            if (ObjectID != "")
                return ObjectID;

            /****
                // check if an Imager layer is selected on the Project Tree
                ObjectID = SGWorld.ProjectTree.GetNextItem("", 10);
        
                if (ObjectID != "") {
                    TEObj = SGWorld.ProjectTree.GetObject(ObjectID);
                    if (TEObj.ObjectType == 26) {
                        return TEObj.ID;
                    }
                }
                ****/
        }
        catch (e) { }

        return "";
    }

    //--------------
    // DetectImageryLayer
    function DetectImageryLayer(x, y) {
        var centerPoint = SGWorld.Window.PixelToWorld(x, y, 4);
        if (centerPoint.Type == 4) {
            var TEObj = SGWorld.Creator.GetObject(centerPoint.ObjectID);
            if (TEObj.ObjectType == 26) {
                return TEObj.ID;
            }
        }
        return "";
    }

    //--------------
    // 
    function SetClipTrans(level, force) {
        if (level == lastlevel && force == false)
            return;
        lastlevel = level;

        // Transparency
        if (document.getElementById("clipDirectionID").value == "4") {
            ImageryLayerObj.Geometry = ImageryLayerGeometry;
            ImageryLayerObj.FillStyle.Color.SetAlpha(level / 100.0);
            document.getElementById("clipSpan").innerHTML = level + "%";
            return;
        }

        // Clipping
        try {
            ImageryLayerObj.FillStyle.Color.SetAlpha(100.0);

            if (level == 100) {
                ImageryLayerObj.Geometry = ImageryLayerGeometry;
                document.getElementById("clipSpan").innerHTML = level + "%";
                return;
            }
            var RightSide = SGWorld.Window.Rect.Width - 1;
            if (document.getElementById("clipDirectionID").value == "0")  // Right 2 Left
                RightSide = RightSide * (level) / 100.0;
            var LeftSide = 0;
            if (document.getElementById("clipDirectionID").value == "1")  // Left 2 Right
                LeftSide = RightSide * (100 - level) / 100.0;
            var BottomSide = SGWorld.Window.Rect.Height - 1;
            if (document.getElementById("clipDirectionID").value == "3")  // Bottom 2 Top
                BottomSide = BottomSide * (level) / 100.0;
            var TopSide = 0;
            if (document.getElementById("clipDirectionID").value == "2")  // Top 2 botton
                TopSide = BottomSide * (100 - level) / 100.0;

            //Try to find the corners of the current terrain view
            var UppLeft = SGWorld.Window.PixelToWorld(LeftSide, TopSide, 0);
            var UppRight = SGWorld.Window.PixelToWorld(RightSide, TopSide, 0);
            var LowerLeft = SGWorld.Window.PixelToWorld(LeftSide, BottomSide, 0);
            var LowerRight = SGWorld.Window.PixelToWorld(RightSide, BottomSide, 0);

            while ((UppLeft.Type & 32) > 0 || (UppRight.Type & 32) > 0) {
                TopSide += SGWorld.Window.Rect.Height / 20;
                if (TopSide > (SGWorld.Window.Rect.Height * 0.9))
                    return;
                UppLeft = SGWorld.Window.PixelToWorld(LeftSide, TopSide, 0);
                UppRight = SGWorld.Window.PixelToWorld(RightSide, TopSide, 0);
            }



            var exteriorRing = SGWorld.Creator.GeometryCreator.CreateLinearRingGeometry(Array(UppLeft.Position.X, UppLeft.Position.Y, 0, UppRight.Position.X, UppRight.Position.Y, 0, LowerRight.Position.X, LowerRight.Position.Y, 0, LowerLeft.Position.X, LowerLeft.Position.Y, 0));
            var PolyGeometry = SGWorld.Creator.GeometryCreator.CreatePolygonGeometry(exteriorRing, null);

            ImageryLayerObj.Geometry = PolyGeometry;

            document.getElementById("clipSpan").innerHTML = level + "%";

            clipPosition = SGWorld.Navigate.GetPosition();
            clearTimeout(ClipUpdatetimeout);
            ClipUpdatetimeout = setTimeout("checkClipUpdate()", 1000);


        }
        catch (e) { alert(SGLang.i18n("Text3") + e.message); }


    }
    //--------------
    // 
    function checkClipUpdate() {
        var currPosition = SGWorld.Navigate.GetPosition()
        if (currPosition.IsEqual(clipPosition) == false) {
            SetClipTrans(lastlevel, true);
        }
        else {
            clearTimeout(ClipUpdatetimeout);
            ClipUpdatetimeout = setTimeout("checkClipUpdate()", 1000);
        }
    }
    //--------------
    // 
    function autoPlay(fromClick) {
        //
        if (fromClick) {
            AutoOnOff = !AutoOnOff;
        }

        if (AutoOnOff) {
            document.getElementById("clipIcon").src = "Images/autoOn.gif";
            var a = sliderClip.getValue();
            a = (a + 2) % 101;
            sliderClip.setValue(a);

            Cliptimeout = setTimeout("autoPlay(false)", 200);

        }
        else {
            document.getElementById("clipIcon").src = "Images/autoOff.gif";
            clearTimeout(Cliptimeout);
        }
    }

    //--------------
    // 
    function exitTool() {
        try {

            SGWorld.SetParam(450, 0);

            if (ImageryLayerObj != null) {
                ImageryLayerObj.FillStyle.Color.SetAlpha(1.0);
                ImageryLayerObj.Geometry = ImageryLayerGeometry;
            }
            SGWorld.Window.RemovePopupByCaption(SGLang.i18n("Text15"));

        }
        catch (e) { }

    }

    </script>
    </head>
    <body onload="Init();" onunload="exitTool();" style="overflow:hidden; border:0; background-color:#535353" leftmargin='0' topmargin="0" marginwidth="0" marginheight="0"> <!-- oncontextmenu="return false;" >-->

    <div id="mainDiv"  style="position:absolute; left:0px; top:0px; overflow:hidden; visibility:hidden; height:100%;">

        <table  cellpadding ="2" cellspacing = "1" border="0" width="100%" height="100%" >
        <tr >
        <td colspan="4" style="color:White" >
            <span class="i18n NormalText" >Text17</span>
            <span class="i18n LayerHeader" id="LayerNameSpan"></span>
        </td>
        </tr>       
       
        <tr>
        <td style="width:140px;" align="right"><span class="i18n NormalText" >Text22</span>
            <select class="directionSelect NormalText" style="vertical-align:middle; width:100px;" id="clipDirectionID" onchange="SetClipTrans(lastlevel,true);">
                <option value="0" class="i18n">Text23</option>
                <option value="1" class="i18n">Text24</option>
                <option value="2" class="i18n">Text25</option>
                <option value="3" class="i18n">Text26</option>
                <option value="4" class="i18n">Text21</option>
            </select>
        </td>
        <td style="color:White; width:210px;" align="left"><span id="sliderClip" style="display:inline-block"><input type="text" id="sliderClipID" /></span></td>

        <td style="width:35px;" align="left"> <span id="clipSpan" class="NormalText" >100%</span></td>

        <td  align="right"  class="SectionText"  onclick="autoPlay(true);" style="cursor:pointer;"><img id="clipIcon" src="Images/autoOff.gif" alt="" align="absmiddle"/> <span class="i18n NormalText" >Text27</span></td>

        </tr>
        </table>
    </div>
    
     <div id="alertDiv"  style="position:absolute; left:0px; top:0px; overflow:hidden; visibility:hidden; height:100%;">
             <table cellpadding ="2" cellspacing = "1" border="1" width="100%" style="height:100%;" >
        <tr >
        <td style="color:White" valign="middle" align="center" class="s10b">
            <span class="i18n" >Text5</span>
        </td>
        </tr>       
        </table>
     </div>

    </body>
</html>




<!--Sig:00000040jX2lBXc1ply601rk50#04OGV8GKFbuSsSRmeHDCs2.A20xXSCXqbn7wSDWQzgcUFWKCz##E2qHl2669J8ZSiX5JJ-->
